<?php
/**
 *+------------------
 * Lflow
 *+------------------
 * Copyright (c) 2023~2030 gitee.com/liu_guan_qing All rights reserved.本版权不可删除，侵权必究
 *+------------------
 * Author: Mr.April(405784684@qq.com)
 *+------------------
 */
declare (strict_types=1);

namespace lflow\workflow;

use lflow\access\DB\PDOAccess;
use lflow\DBAccess;

/**
 * 抽象父类，提供给子类access实现方式
 *
 * @author Mr.April
 * @since  1.0
 */
abstract class AccessService
{
    /**
     * 状态；活动状态
     */
    const  STATE_ACTIVE = 1;

    /**
     * 状态：结束状态
     */
    const  STATE_FINISH = 0;

    /**
     * 状态：终止状态
     */
    const  STATE_TERMINATION = 2;

    /**
     * @var \lflow\DBAccess
     */
    protected DBAccess $access;

    public function __construct()
    {
        $PDO = PDOAccess::getConnection();
        $this->setAccess($PDO);
    }

    /**
     * setter
     *
     * @param \lflow\DBAccess $access
     */
    public function setAccess(DBAccess $access): void
    {
        $this->access = $access;
    }

    /**
     * access  供子类使用
     *
     * @return \lflow\DBAccess
     */
    public function access(): DBAccess
    {
        return $this->access;
    }

    /**
     * 启动事务
     */
    public function beginTransaction(): void
    {
        $this->access()->beginTransaction();
    }

    /**
     * 事务回滚
     */
    public function rollback(): void
    {
        $this->access()->rollback();
    }

    /**
     * 事务提交
     */
    public function commit(): void
    {
        $this->access()->commit();
    }

}
